home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5938 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.0 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Easiest way to center a string?
  5. Date: 21 Feb 1996 15:26:44 GMT
  6. Organization: Los Alamos National Laboratory
  7. Distribution: world
  8. Message-ID: <TANMOY.96Feb21082644@qcd.lanl.gov>
  9. References: <4fobka$1st@parlor.hiwaay.net> <DMqEG5.8z4@eskimo.com>
  10.     <4frif5$e6p@fohnix.metronet.com> <DMuuzG.1yK@eskimo.com>
  11.     <4gbmmo$m5v@airdmhor.gen.nz>
  12.     <Pine.A32.3.91.960220105403.86291D-100000@red.weeg.uiowa.edu>
  13.     <TANMOY.96Feb20163829@qcd.lanl.gov>
  14.     <Pine.A32.3.91.960221001254.156335E-100000@black.weeg.uiowa.edu>
  15. NNTP-Posting-Host: qcd.lanl.gov
  16. Mime-Version: 1.0
  17. Content-Type: text
  18. In-reply-to: The Amorphous Mass's message of Wed, 21 Feb 1996 00:17:44 -0600
  19.  
  20. In article
  21. <Pine.A32.3.91.960221001254.156335E-100000@black.weeg.uiowa.edu> The
  22. Amorphous Mass <robinson@blue.weeg.uiowa.edu> writes: 
  23. <snip>
  24.    > In article Amorphous Mass <robinson@blue.weeg.uiowa.edu> writes: 
  25.    > <snip>
  26.    >      That's equivalent to strlen(String + -LineLen), which is in turn 
  27.    >    equivalent to strlen(String[-LineLen]), and the expression String[-80] is 
  28.  
  29.                              ^ this is now a char, not a char*.
  30.  
  31.    >    portable only in the sense that its behavior is undefined on all 
  32.    >    platforms. :)
  33.    > 
  34.    > Sorry there is no trigraph for `&': so if that key is broken, you just
  35.    > have to get it fixed :-)
  36.  
  37.    ???  Works fine.  My tilde key is broken though, which makes UNIX a real 
  38.    pain.
  39.  
  40.    > 
  41.    >      If you meant (strlen(String) - LineLen) / 2 then you will get a 
  42.    >    negative length specifier for any string with fewer than LineLen 
  43.    >    characters.  If you meant (LineLen - strlen(String) / 2, then your 
  44.    > 
  45.    > strlen returns size_t which is guaranteed unsigned. (I am assuming
  46.    > LineLen is not long.)
  47.  
  48.      Right, but strlen(String) would be 12, minus LineLen which is 80, which 
  49.    is -68, divided by two is -34, which is the number passed as a width 
  50.  
  51. but if size_t is unsigned int or unsigned long, and LineLen is int,
  52. the result is not -68 because an unsigned quantity cannot be -68. (My
  53. parenthetical remark was wrong: I had assumed that size_t was at least
  54. as long as unsigned int and LineLen is not long).
  55.  
  56.    specifier to printf().  I don't think printf("%*s", -34, "hello, world); 
  57.    is worth much. :)
  58.  
  59. Neither is the unsigned number that you get.
  60.  
  61. By the way, I thought the * specifier needs an int, an unsigned int
  62. will not do.
  63.  
  64.      I guess I didn't say that at all clearly the first time.  Is it clearer 
  65.    now, or am I _completely_ brain-dead?
  66.  
  67. I was not clear either.
  68.  
  69. Cheers
  70. Tanmoy
  71. --
  72. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  73. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  74. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  75. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  76. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  77. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  78.